/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.border.Border;

/**
 *
 * @author Juan
 */
public class LoadImageDesktopPane {
    private File image;
    
    public LoadImageDesktopPane() {
        image = new File (ClientConfiguration.getImagenes()+"Chat.jpg");
    }
   
    
    public File getImage(){
        return image;
    }
    
    /*este metodo recibe el jdeskopPane y el archivo imagen*/
    public  void cargarImagen(javax.swing.JDesktopPane jDeskp,File fileImagen)
    {
        try{
            BufferedImage image = ImageIO.read(fileImagen);
              jDeskp.setBorder(new PintaImagen(image)); 
        }
        catch (Exception e){   
            System.out.println("Error Loading the image ");   
        }
    }
    
    public class PintaImagen implements Border{

        private   BufferedImage image ;

        public PintaImagen(BufferedImage image ) {
            this.image=image;}

            public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
                int x0 = x+ (width-image.getWidth())/2;
                int y0 = y+ (height-image.getHeight())/2;
                g.drawImage(image,x0,y0,null); 
            }

            public Insets getBorderInsets(Component c) {
                return new Insets(0,0,0,0);
            }

            public boolean isBorderOpaque() {
                return true; 
            }
    }
    
}
